Conditions | 1 |
Paths | 4 |
Total Lines | 121 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var spauth = require('node-sp-auth'); |
||
10 | .then(function (data) { |
||
11 | var internalQueryStructureGeneric = MyCustomFunctions.internalQueryStructureArray(0); |
||
12 | var ListNameArray = []; |
||
13 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, '', 'Lists', data)).then(function (response) { |
||
14 | var dataObjectLists = response.d.results; |
||
15 | if (Object.keys(dataObjectLists).length > 0) { |
||
16 | var wStreamListViews = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Views + '.csv', {encoding: 'utf8'}); // initiate MetaData for Views |
||
17 | wStreamListViews.write('"List Name"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.Views).join('"' + config.General.ListSeparator + '"') + '"\n'); // Headers for Views |
||
18 | var dataListLight = []; |
||
19 | var counter = 0; |
||
20 | dataObjectLists.forEach(function (item) { |
||
21 | dataListLight[counter] = MyCustomFunctions.buildCurrentListAttributeValues(config.SharePoint.MetaDataOutput.Lists, item); |
||
22 | ListNameArray[counter] = item.Title; |
||
23 | counter++; |
||
24 | }); |
||
25 | var wStreamList = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Lists + '.csv', {encoding: 'utf8'}); // initiate MetaData for Lists |
||
26 | wStreamList.write('"' + Object.keys(dataListLight[0]).join('"' + config.General.ListSeparator + '"') + '"\n'); // headers of MetaData for Lists |
||
27 | var wStreamListFields = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Fields + '.csv', {encoding: 'utf8'}); // initiate MetaData for Fields |
||
28 | wStreamListFields.write('"List"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.Fields).join('"' + config.General.ListSeparator + '"') + '"\n'); // headers of MetaData for Fields |
||
29 | dataListLight.forEach(function (crtListParameters) { // parse each List |
||
30 | if (MyCustomFunctions.decideBlackListWhiteList(crtListParameters.Hidden, false, config.SharePoint.Filters.Lists.NotHidden.BlackList, true, config.SharePoint.Filters.Lists.Hidden.WhiteList, crtListParameters.Title)) { // check current List against configured BlackList and WhiteList besides considering user defined Lists |
||
31 | wStreamList.write('"' + Object.keys(crtListParameters).map(function (x) { // records detail of current List |
||
32 | return crtListParameters[x]; |
||
33 | }).join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
34 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Fields', data)).then(function (response) { // Dynamically detect structure of the list, extracting the Field names and their text to display |
||
35 | var dataObject = response.d.results; |
||
36 | if (Object.keys(dataObject).length > 0) { |
||
37 | var fieldAttributes = []; |
||
38 | var counter = 0; |
||
39 | dataObject.forEach(function (item) { |
||
40 | var crtRecordFieldWillBeExtracted = MyCustomFunctions.decideBlackListWhiteList(item.CanBeDeleted, true, config.SharePoint.Filters.Fields.CanBeDeleted.BlackList, false, config.SharePoint.Filters.Fields.CannotBeDeleted.WhiteList, item.InternalName); // check current Field against configured BlackList and WhiteList besides considering user defined Fields |
||
41 | if (config.SharePoint.Filters.Lists.Hidden.WhiteList.indexOf(crtListParameters.Title) > -1) { // for certain Lists all existing fields should be retrieved |
||
42 | crtRecordFieldWillBeExtracted = true; |
||
43 | } |
||
44 | if (crtRecordFieldWillBeExtracted) { |
||
45 | fieldAttributes[item.Title] = { |
||
46 | 'Technical Name': item.StaticName, |
||
47 | 'Type': item.TypeAsString |
||
48 | }; |
||
49 | counter++; |
||
50 | var crtListField = []; |
||
51 | var counterF = 0; |
||
52 | Object.keys(config.SharePoint.MetaDataOutput.Fields).forEach(function (itemF) { |
||
53 | crtListField[counterF] = item[config.SharePoint.MetaDataOutput.Fields[itemF]]; |
||
54 | counterF++; |
||
55 | }); |
||
56 | wStreamListFields.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + crtListField.join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
57 | } |
||
58 | }); |
||
59 | var internalQueryStructureItem = MyCustomFunctions.internalQueryStructureArray(crtListParameters.Records); |
||
60 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureItem, crtListParameters.Title, 'Items', data)).then(function (response) { // Get the actual values from current list |
||
61 | var wstream = fs.createWriteStream(config.General.PathForExtracts + crtListParameters.Title + '.csv', {encoding: 'utf8'}); |
||
62 | wstream.write('"' + Object.keys(fieldAttributes).join('"' + config.General.ListSeparator + '"') + (crtListParameters['Versioning Enabled'] ? '"' + config.General.ListSeparator + '"Version' : '') + '"\n'); // writing headers for records within current list |
||
63 | var dataObjectValues = response.d.results; |
||
64 | if (Object.keys(dataObjectValues).length > 0) { |
||
65 | dataObjectValues.forEach(function (item) { |
||
66 | var crtRecord = MyCustomFunctions.buildCurrentItemValues(fieldAttributes, item); |
||
67 | wstream.write('"' + crtRecord.join('"' + config.General.ListSeparator + '"') + (crtListParameters['Versioning Enabled'] ? '"' + config.General.ListSeparator + '"' + item.OData__UIVersionString : '') + '"\n'); // writing current record values |
||
68 | }); |
||
69 | } |
||
70 | wstream.end(); |
||
71 | }); |
||
72 | } |
||
73 | }); |
||
74 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Views', data)).then(function (responseViews) { |
||
75 | var dataViewObject = responseViews.d.results; |
||
76 | if (Object.keys(dataViewObject).length > 0) { |
||
77 | dataViewObject.forEach(function (crtView) { |
||
78 | var crtRecordView = []; |
||
79 | var counterV = 0; |
||
80 | Object.keys(config.SharePoint.MetaDataOutput.Views).map(function (itemV) { |
||
81 | if (config.SharePoint.MetaDataOutput.Views[itemV] === 'HtmlSchemaXml') { |
||
82 | crtRecordView[counterV] = JSON.stringify(crtView[config.SharePoint.MetaDataOutput.Views[itemV]]); |
||
83 | } else { |
||
84 | crtRecordView[counterV] = crtView[config.SharePoint.MetaDataOutput.Views[itemV]]; |
||
85 | } |
||
86 | counterV++; |
||
87 | }); |
||
88 | wStreamListViews.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + crtRecordView.join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
89 | }); |
||
90 | } |
||
91 | }); |
||
92 | } |
||
93 | }); |
||
94 | wStreamList.end(); |
||
95 | } |
||
96 | }); |
||
97 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, '', 'SiteGroups', data)).then(function (response) { |
||
98 | var dataObjectValues = response.d.results; |
||
99 | if (Object.keys(dataObjectValues).length > 0) { |
||
100 | var wStreamGroups = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.SiteGroups + '.csv', {encoding: 'utf8'}); // initiate MetaData for Groups |
||
101 | wStreamGroups.write('"' + Object.keys(config.SharePoint.MetaDataOutput.SiteGroups).join('"' + config.General.ListSeparator + '"') + '"\n'); // Headers for Groups |
||
102 | var wStreamGroupMembers = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.SiteGroupMembers + '.csv', {encoding: 'utf8'}); // initiate MetaData for Group Members |
||
103 | wStreamGroupMembers.write('"Group"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.SiteGroupMembers).join('"' + config.General.ListSeparator + '"') + '"\n'); // Headers for Group Members |
||
104 | dataObjectValues.forEach(function (crtItemGroup) { |
||
105 | var crtRecord = []; |
||
106 | var counterG = 0; |
||
107 | Object.keys(config.SharePoint.MetaDataOutput.SiteGroups).map(function (itemG) { |
||
108 | crtRecord[counterG] = crtItemGroup[config.SharePoint.MetaDataOutput.SiteGroups[itemG]]; |
||
109 | counterG++; |
||
110 | }); |
||
111 | wStreamGroups.write('"' + crtRecord.join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
112 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtItemGroup.Id, 'GroupMembers', data)).then(function (responseMembers) { |
||
113 | var dataObjectMemberValues = responseMembers.d.results; |
||
114 | if (Object.keys(dataObjectMemberValues).length > 0) { |
||
115 | dataObjectMemberValues.forEach(function (crtItemGroupMember) { |
||
116 | var crtRecordGM = []; |
||
117 | var counterGM = 0; |
||
118 | Object.keys(config.SharePoint.MetaDataOutput.SiteGroupMembers).map(function (itemGM) { |
||
119 | crtRecordGM[counterGM] = crtItemGroupMember[config.SharePoint.MetaDataOutput.SiteGroupMembers[itemGM]]; |
||
120 | counterGM++; |
||
121 | }); |
||
122 | wStreamGroupMembers.write('"' + crtItemGroup.Title + '"' + config.General.ListSeparator + '"' + crtRecordGM.join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
123 | }); |
||
124 | } |
||
125 | }); |
||
126 | }); |
||
127 | wStreamGroups.end(); |
||
128 | } |
||
129 | }); |
||
130 | }); |
||
131 |